package com.ruoyi.canteen.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.canteen.domain.OrderRecord;
import com.ruoyi.canteen.service.IOrderRecordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 报餐记录Controller
 *
 * @author ruoyi
 * @date 2025-04-02
 */
@RestController
@RequestMapping("/canteen/record")
public class OrderRecordController extends BaseController
{
    @Autowired
    private IOrderRecordService orderRecordService;

    /**
     * 查询报餐记录列表
     */
    @PreAuthorize("@ss.hasPermi('canteen:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(OrderRecord orderRecord)
    {
        startPage();
        List<OrderRecord> list = orderRecordService.selectOrderRecordList(orderRecord);
        return getDataTable(list);
    }

    /**
     * 导出报餐记录列表
     */
    @PreAuthorize("@ss.hasPermi('canteen:record:export')")
    @Log(title = "报餐记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OrderRecord orderRecord)
    {
        List<OrderRecord> list = orderRecordService.selectOrderRecordList(orderRecord);
        ExcelUtil<OrderRecord> util = new ExcelUtil<OrderRecord>(OrderRecord.class);
        util.exportExcel(response, list, "报餐记录数据");
    }

    /**
     * 获取报餐记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('canteen:record:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(orderRecordService.selectOrderRecordById(id));
    }

    /**
     * 新增报餐记录
     */
    @PreAuthorize("@ss.hasPermi('canteen:record:add')")
    @Log(title = "报餐记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OrderRecord orderRecord)
    {
        return toAjax(orderRecordService.insertOrderRecord(orderRecord));
    }

    /**
     * 修改报餐记录
     */
    @PreAuthorize("@ss.hasPermi('canteen:record:edit')")
    @Log(title = "报餐记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OrderRecord orderRecord)
    {
        return toAjax(orderRecordService.updateOrderRecord(orderRecord));
    }

    /**
     * 删除报餐记录
     */
    @PreAuthorize("@ss.hasPermi('canteen:record:remove')")
    @Log(title = "报餐记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(orderRecordService.deleteOrderRecordByIds(ids));
    }
}
